import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login.vue'
import Main from '@/views/Main.vue'
import Home from "@/views/Home.vue";

Vue.use(VueRouter)

const routes = [
    /*  {
        path: '/',
        name: 'home',
        component: HomeView
      },
      {
        path: '/about',
        name: 'about',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/!* webpackChunkName: "about" *!/ '../views/AboutView.vue')
      }*/
    // 默认请求/，重定向到/login
    { path: '/', redirect: '/login' },
    { path: '/login', name: 'login', component: Login },
    {
        path: '/main', name: 'main', component: Main,
        children: [
            {
                path: '/main/home',
                component: Home,
            },
            {
                path: '/main/article',
                component: () => import('@/views/Article.vue')
            },
            {
                path: '/main/goods-selected',
                name: '/goods-selected',
                component: () => import('@/views/fm.vue')
            },
            {
                path: '/main/notice',
                name: '/notice',
                component: () => import('@/views/Notice.vue')
            },
            {
                path: '/main/order-selected',
                name: '/order-selected',
                component: () => import('@/views/ArticleType.vue')
            },
            // {
            // 		    path: '/main/sales-selected',
            // 		    name: '/sales-selected',
            // 		    component: () => import('@/views/sales-selected.vue')
            // 		},
            {
                path: '/main/zxsgl',
                name: '/zxsgl',
                component: () => import('@/views/zxsgl.vue')
            },
            {
                path: '/main/order-selected',
                name: 'order-selected',
                component: () => import('@/views/HeartMark.vue')
            },
            {
                path: '/main/Appointment',
                name: 'Appointment',
                component: () => import('@/views/Appointment.vue')
            },
            {
                path: '/main/Usermark',
                name: 'Usermark',
                component: () => import('@/views/Usermark.vue')
            }, {
                path: '/main/sales-selected',
                name: '/sales-selected',
                component: () => import('@/views/sales-selected.vue')
            },
            {
                path: '/main/zxsgl',
                name: '/zxsgl',
                component: () => import('@/views/zxsgl.vue')
            },
            {
                path: '/main/courseType',
                component: () => import('../components/content/courseType.vue')
            },
            {
                path: '/main/courseManager',
                component: () => import('../components/content/courseManager.vue')
            },
            {
                path: '/main/courseMark',
                component: () => import('../components/content/courseMark.vue')
            },
            {
                path: '/main/company',
                component: () => import('../components/system/company.vue')
            },
            {
                path: '/main/heartMark',
                name: '/heartMark',
                component: () => import('@/views/HeartMark.vue')
            },
            {
                path: '/main/free',
                name: '/free',
                component: () => import('@/views/Free.vue')
            },
            {
                path: '/main/user',
                name: '/user',
                component: () => import('@/views/User.vue')
            },
            {
                path: '/main/Specialty',
                name: 'Specialty',
                component: () => import('@/views/Specialty.vue')
            },
            {
                path: '/main/Charge',
                name: 'Charge',
                component: () => import('@/views/Charge.vue')
            },
            {
                path: '/main/ChargeType',
                name: 'ChargeType',
                component: () => import('@/views/ChargeType.vue')
            },
            {
                path: '/main/reply',
                name: '/reply',
                component: () => import('@/views/Reply.vue')
            },
            {
                path: "/main/shop-service",
                name: "shop-service",
                component: () => import("@/views/Systemuser.vue"),
              },
              {
                path: "/main/question-manage",
                name: "question-manage",
                component: () => import("@/views/Question.vue"),
              },
              {
                path: "/main/publicity",
                name: "publicity",
                component: () => import("@/views/Publicity.vue"),
              }
        ]
    }
]

const router = new VueRouter({
    routes
})

// 挂载路由导航守卫,to表示将要访问的路径，from表示从哪里来，next是下一个要做的操作
// 添加路由守卫
// to:要去访问的请求名   from：从哪里出发    next:下一个请求，进行跳转
router.beforeEach((to,from,next)=>{
	if(to.path === '/login'){
		return next();  // 放行
	}
	// 动态的获取sessionStorage中的数据
	let username = sessionStorage.getItem('username');
	if(!username){   // 没有登录，则跳转到登录页面
		
		return next('/login');   
	}
	// 如果登录则放行
	next();
})


export default router
